import 'package:flutter/material.dart';
import 'package:heven/pages/home/home.dart';
import 'package:heven/pages/creation/creation.dart';
import 'package:heven/pages/set/set.dart';
import 'package:heven/pages/vip/vip.dart';
import 'pages/login/login.dart';
import 'pages/login/list.dart';
import 'package:heven/pages/music/music.dart';
import 'package:heven/pages/agree/agree.dart';

//

Map<String, WidgetBuilder>? _routes = {
  '/home': (context, {arguments}) => HomePage(arguments: arguments),
  '/creation': (context) => const CreationPage(),
  '/set': (context, {arguments}) => SetPage(arguments: arguments),
  '/vip': (context) => const VipPage(),
  '/login': (context) => const LoginPage(),
  '/login/list': (context) => const LoginListPage(),
  '/music': (context) => const MusicPage(),
  '/agree': (context, {arguments}) => AgreePage(arguments: arguments),
};
var onGenerateRoute = (RouteSettings settings) {
  //因为我们页面跳转和传参数会有很多情况，
  //于是做一个通用的路由接收是有必要的
  //1.获取当前调用的路由名称
  String? routeName = settings.name;
  //2.找到我们上面定义的Map路由表中是否包含此路由，并取出方法
  Function pageContentBuilder = _routes?[routeName] as Function;
  //3.判断不为null表示找到了某个路由定义的方法
  if (pageContentBuilder != null) {
    //4.判断setting中的 arguments 不为null
    if (settings.arguments != null) {
      //5.返回要跳转的页面和传递参数
      final Route route = MaterialPageRoute(
          //6.使用我们获取到的Function 调用带参数的去传递参数
          builder: (context) =>
              pageContentBuilder(context, arguments: settings.arguments));
      return route;
    } else {
      //7.否则使用我们获取到的Function 调用不带参数的
      return MaterialPageRoute(
          builder: (context) => pageContentBuilder(context));
    }
  }
};
